package cn.admin.common.domain;

import cn.admin.common.enumeration.ResponseEnum;

/**
 * @author YJ
 * @DateTime 2023/2/21 13:52
 */
public class Result<T>{

    /**
     * 状态码
     */
    private int code;


    /**
     * 响应信息
     */
    private String message;

    /**
     * 响应数据
     */
    private T data;


    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setCode(ResponseEnum.success.getCode());
        result.setMessage(ResponseEnum.success.getMessage());
        result.setData(data);
        return result;
    }


    public static <T> Result<T> success(){
        return success(null);
    }


    public static <T> Result<T> error(int code, String message){
        Result<T> result = new Result<>();
        result.setCode(0 == code ? ResponseEnum.error.getCode():code);
        result.setMessage(null == message ? ResponseEnum.error.getMessage() : message);
        return result;
    }

    public static <T> Result<T> error(String message) {
        return error(0, message);
    }

    public static <T> Result<T> error() {
        return error(null);
    }




    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
